home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
cone
/
esc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-06
|
11KB
|
620 lines
/*
超突貫シェル???
ESC
*/
#include <stdio.h>
#include <string.h>
typedef enum {
EXIT_ESC,
USER_FUNC,
SYSTEM,
ADD_IVENT,
IDLE,
WRITE_TEXT,
TITLE,
JPG_UL,
JPG_UR,
JPG_DL,
JPG_DR,
PIC_UL,
PIC_UR,
PIC_DL,
PIC_DR
} FUNC_NUMBER;
typedef struct {
char func_name[64+1]; //関数名
int func_argc; //コマンドラインのアレ
char func_argv[16][64+1]; //コマンドライン
} FUNC_INFO;
typedef struct {
int px,py,ox,oy; //ボタン位置
char func_name[64+1]; //関数名
} IVENT_LIST;
typedef struct {
int mx,my; //ボタン位置
} PUSH_INFO;
IVENT_LIST global_list[4];
int main(argc,argv)
int argc;
char *argv[];
{
Init();
if( argc==2 ){
Escape(argv[1],"main");
}
else{
printf("usage : ESC filename\n");
}
}
/*
グローバルボタン設定
*/
int Init()
{
global_list[0].px=488;
global_list[0].py=4;
global_list[0].ox=16;
global_list[0].oy=16;
strcpy(global_list[0].func_name,"exit");
global_list[1].px=8;
global_list[1].py=56;
global_list[1].ox=20;
global_list[1].oy=20;
strcpy(global_list[1].func_name,"return");
screen(1,3,1,1);
apic_load("esc_form.pic",0,0);
}
/*
終了
*/
int Term()
{
screen(2,0,1,1);
exit(1);
}
/*
ESC実行
script スクリプトファイル名
funcname 関数名
0未満で異常終了
*/
int Escape(script,funcname)
char *script,*funcname;
{
int res=0,fres;
FILE *script_fp;
char linebuf[256],*lptr; //ファイルリード用ラインバッファ
char search_string[256],*sptr; //サーチ文字格納
FUNC_INFO func_info[16]; //実行コマンド(数は適当)
int fn=0,last_func; //実行ナンバー
IVENT_LIST ivent_list[16]; //イベントリスト
int in=0,last_ivent; //イベントナンバー
int md,mbl,mbr,mx,my;
PUSH_INFO push_info; //退避情報
cls();
OS_CUROF();
C_FNKMOD(2);
//Location
fill(80,88,420,106,rgb(27,27,27));
symbol(80,88,script,1,1,1,rgb(1,1,1),0);
//mes
{
char *mes,buf[256];
mes=buf;
sprintf(mes,"%sを処理中",funcname);
PrintMes(mes);
}
mouse(0);
mouse(1);
mouse(4);
script_fp=fopen(script,"rt");
if( script_fp==NULL ){
res=-1;
printf("スクリプトファイルが開けません");
getch();
goto quick_exit;
}
//検索関数名の設定
sptr=search_string;
strcpy(sptr,"func ");
strcat(sptr,funcname);
strcat(sptr,"()");
while(1){
fres=fgets(linebuf,256,script_fp);
if( fres==NULL ){
break; //ファイルを読み込み終わった
}
if( linebuf[0]=='/' || linebuf[0]=='\x0' || linebuf[0]=='\x0d' || linebuf[0]=='\x0a' ){
continue;
}
delcrlf(linebuf);
fres=strcmp(linebuf,search_string);
if( fres==0 ){
//関数名発見
fn=0;
while(1){
fres=fgets(linebuf,256,script_fp);
if( fres==NULL ){ //異常終了?
goto quick_exit;
}
if( linebuf[0]=='/' || linebuf[0]=='\x0' || linebuf[0]=='\x0d' || linebuf[0]=='\x0a' ){
continue;
}
delcrlf(linebuf);
if( strcmp("endfunc",linebuf)==0 ){
goto read_escfile_exit;
}
fres=GetFuncInfo(linebuf,&func_info[fn]);
fn++;
}
break;
}
}
read_escfile_exit:
fclose(script_fp);
last_func=fn-1;
PushInfo(&push_info);
DrawFuncInfo(script,&func_info,last_func);
PopInfo(&push_info);
mouse(1);
mouse(4);
//mes
PrintMes("読み終わりました");
in=0;
for( fn=0;fn<=last_func;fn++ ){
char comline[256],*cl;
fres=GetFuncNumber(&(func_info[fn]));
switch( fres ){
//イベント追加
case ADD_IVENT:
strcpy(ivent_list[in].func_name,func_info[fn].func_argv[0]);
sscanf(func_info[fn].func_argv[1],"%d,%d,%d,%d",
&(ivent_list[in].px),&(ivent_list[in].py),&(ivent_list[in].ox),&(ivent_list[in].oy));
in++;
break;
case IDLE:
last_ivent=in-1;
while(1){
mspos(&mx,&my);
msstat(&md,&md,&mbl,&mbr);
if( mbl==-1 ){
//ローカルボタンイベント
for( in=0;in<=last_ivent;in++ ){
if(
mx>ivent_list[in].px && my>ivent_list[in].py &&
mx<(ivent_list[in].px+ivent_list[in].ox) && my<(ivent_list[in].py+ivent_list[in].oy)
){
PushInfo(&push_info);
Escape(script,ivent_list[in].func_name);
DrawFuncInfo(script,&func_info,last_func);
PrintMes("復帰完了");
PopInfo(&push_info);
}
}
//グローバルボタンイベント
for( in=0;in<=1;in++ ){
if(
mx>global_list[in].px && my>global_list[in].py &&
mx<(global_list[in].px+global_list[in].ox) && my<(global_list[in].py+global_list[in].oy)
){
if( strcmpi(global_list[in].func_name,"exit")==0 ){
Term();
}
if( strcmpi(global_list[in].func_name,"return")==0 ){
goto quick_exit;
}
}
}
}
if( mbl==-1 && mbr==-1 ){
break;
}
}
break;
}
}
quick_exit:
PrintMes("復帰中");
return(0);
}
int DrawFuncInfo(script,func_info,last_func)
char *script;
FUNC_INFO *func_info;
int last_func;
{
int fn,fres;
for( fn=0;fn<=last_func;fn++ ){
char comline[256],*cl;
fres=GetFuncNumber(&func_info[fn]);
switch( fres ){
case SYSTEM:
Func__system(&func_info[fn]);
break;
case JPG_UL:
Func__jpg_load_ul(&func_info[fn]);
break;
case JPG_UR:
Func__jpg_load_ur(&func_info[fn]);
break;
case JPG_DL:
Func__jpg_load_dl(&func_info[fn]);
break;
case JPG_DR:
Func__jpg_load_dr(&func_info[fn]);
break;
case PIC_UL:
apic_load(func_info[fn].func_argv[0],8,128);
break;
case PIC_UR:
apic_load(func_info[fn].func_argv[0],248,128);
break;
case PIC_DL:
apic_load(func_info[fn].func_argv[0],8,308);
break;
case PIC_DR:
apic_load(func_info[fn].func_argv[0],248,308);
break;
case WRITE_TEXT:
WriteText(func_info[fn].func_argv[0]);
break;
case USER_FUNC:
Escape(script,func_info[fn].func_argv[0]);
break;
case EXIT_ESC:
Term();
break;
case TITLE:
PrintTitle(func_info[fn].func_argv[0]);
break;
}
}
}
/*
文字列からCRLFを取り除く
*/
int delcrlf(ptr)
char *ptr;
{
while( !(*ptr=='\x0d' || *ptr=='\x0a' || *ptr=='\x00') ){
ptr++;
}
*ptr=NULL;
}
/*
関数
*/
int GetFuncInfo(linebuf,func_info)
char *linebuf;
FUNC_INFO *func_info;
{
int res=0;
char *source,*dest,*av;
int ac;
source=linebuf;
//関数名検出
//頭の空白スキップ
while(1){
if( *source=='\t' || *source==' ' ){
source++;
}
else{
if( *source=='\n' || *source==NULL ){
res=-1;
goto quick_exit;
}
break;
}
}
//関数名摘出
dest=func_info->func_name;
while(1){
if( *source=='(' ){ //関数名終わり
*dest=NULL;
source++;
break;
}
if( *source=='\n' ){ //他にも構文解析が必要
res=-2;
goto quick_exit;
}
*dest++=*source++;
}
//パラメ検出
ac=0;
while(1){
//頭の"検索
while(1){
if( *source=='"' ){
source++;
break;
}
//エラーチェック入れること
source++;
}
//中身抜き出し
dest=&(func_info->func_argv[ac][0]);
while(1){
if( *source=='"' ){
*dest=NULL;
source++;
break;
}
//エラーチェック入れること
*dest++=*source++;
}
//後始末
while(1){
if( *source==',' ){
ac++;
source++;
break;
}
if( *source==')' ){
goto av_end;
}
//エラーチェック入れること
}
av_next:
;
}
av_end:
func_info->func_argc=ac+1;
quick_exit:
return(res);
}
/*
関数の番号を返す
*/
FUNC_NUMBER GetFuncNumber(func_info)
FUNC_INFO *func_info;
{
int res=USER_FUNC;
if( strcmpi("system",func_info->func_name)==0 ){
res=SYSTEM;
goto quick_exit;
}
if( strcmpi("jpg_load_ul",func_info->func_name)==0 ){
res=JPG_UL;
goto quick_exit;
}
if( strcmpi("jpg_load_ur",func_info->func_name)==0 ){
res=JPG_UR;
goto quick_exit;
}
if( strcmpi("jpg_load_dl",func_info->func_name)==0 ){
res=JPG_DL;
goto quick_exit;
}
if( strcmpi("jpg_load_dr",func_info->func_name)==0 ){
res=JPG_DR;
goto quick_exit;
}
if( strcmpi("pic_load_ul",func_info->func_name)==0 ){
res=PIC_UL;
goto quick_exit;
}
if( strcmpi("pic_load_ur",func_info->func_name)==0 ){
res=PIC_UR;
goto quick_exit;
}
if( strcmpi("pic_load_dl",func_info->func_name)==0 ){
res=PIC_DL;
goto quick_exit;
}
if( strcmpi("pic_load_dr",func_info->func_name)==0 ){
res=PIC_DR;
goto quick_exit;
}
if( strcmpi("write_text",func_info->func_name)==0 ){
res=WRITE_TEXT;
goto quick_exit;
}
if( strcmpi("mbl_down",func_info->func_name)==0 ){
res=ADD_IVENT;
goto quick_exit;
}
if( strcmpi("idle",func_info->func_name)==0 ){
res=IDLE;
goto quick_exit;
}
if( strcmpi("exit",func_info->func_name)==0 ){
res=EXIT_ESC;
goto quick_exit;
}
if( strcmpi("title",func_info->func_name)==0 ){
res=TITLE;
goto quick_exit;
}
quick_exit:
return(res);
}
/*****************************************************
内部関数
******************************************************/
int Func__system(func_info)
FUNC_INFO *func_info;
{
system(func_info->func_argv[0]);
}
int Func__jpg_load_ul(func_info)
FUNC_INFO *func_info;
{
char *cl,comline[256];
cl=comline;
strcpy(cl,"JPEGED -N -F3 -L8,128,247,307 ");
strcat(cl,func_info->func_argv[0]);
strcat(cl," > NUL ");
system(comline);
}
int Func__jpg_load_ur(func_info)
FUNC_INFO *func_info;
{
char *cl,comline[256];
cl=comline;
strcpy(cl,"JPEGED -N -F3 -L248,128,487,307 ");
strcat(cl,func_info->func_argv[0]);
strcat(cl," > NUL ");
system(comline);
}
int Func__jpg_load_dl(func_info)
FUNC_INFO *func_info;
{
char *cl,comline[256];
cl=comline;
strcpy(cl,"JPEGED -N -F3 -L8,308,247,487 ");
strcat(cl,func_info->func_argv[0]);
strcat(cl," > NUL ");
system(comline);
}
int Func__jpg_load_dr(func_info)
FUNC_INFO *func_info;
{
char *cl,comline[256];
cl=comline;
strcpy(cl,"JPEGED -N -F3 -L248,308,487,487 ");
strcat(cl,func_info->func_argv[0]);
strcat(cl," > NUL ");
system(comline);
}
int PushInfo(push_info)
PUSH_INFO *push_info;
{
mspos(&(push_info->mx),&(push_info->my));
}
int PopInfo(push_info)
PUSH_INFO *push_info;
{
mouse(1);
mouse(4);
setmspos(push_info->mx,push_info->my);
}
int PrintMes(mes)
{
fill(72,492,324,504,rgb(23,23,23));
symbol(72,492,mes,1,1,0,rgb(1,1,1),0);
}
int PrintTitle(mes)
{
fill(24,6,488,22,rgb(0,0,25));
symbol(24,6,mes,1,1,1,rgb(27,27,27),0);
}